﻿//AcademicPlanner - course registration planning web app.
//Copyright (C) 2009  Boubacar Diallo

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AcademicPlanner.Domain
{
	/// <summary>
	/// DomainException is the base class for all application level exceptions
	/// in the domain layer of the AcademicPlanner application.
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
    abstract public class DomainException : ApplicationException
    {
		/// <summary>
		/// The error code associated with this DomainException.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		protected DomainErrorCode errorCode;


		/// <summary>
		/// Gets the error code associated with this DomainException.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public DomainErrorCode ErrorCode { get { return errorCode; } }

		/// <summary>
		/// Gets the error message associated with this DomainException based on its error code.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public override string Message { get { return GetErrorCodeMessage(errorCode); } }


		/// <summary>
		/// Constructs a DomainException by initializing its <c>errorCode</c> with the given
		/// <c>DomainErrorCode</c>.
		/// </summary>
		/// <param name="pCode">The <c>DomainErrorCode</c> for this DomainException.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public DomainException(DomainErrorCode pCode) : base()
		{
			errorCode = pCode;
		}

		/// <summary>
		/// Constructs a DomainException by initializing its <c>errorCode</c> with the given
		/// <c>DomainErrorCode</c> and its <c>InnerException</c> with the given <c>Exception</c>.
		/// </summary>
		/// <param name="pCode">The <c>DomainErrorCode</c> for this DomainException.</param>
		/// <param name="pInnerException">The <c>InnerException</c> for this DomainException.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public DomainException(DomainErrorCode pCode, Exception pInnerException)
			: base("", pInnerException)
		{
			errorCode = pCode;
		}


		/// <summary>
		/// Gets the error message associated with a given <c>DomainErrorCode</c>.
		/// </summary>
		/// <param name="pCode">The <c>DomainErrorCode</c> to get the associated message with.</param>
		/// <returns>The error message associated with the given <c>DomainErrorCode</c>.</returns>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public static string GetErrorCodeMessage(DomainErrorCode pCode)
		{
#if DEBUG
			return pCode.ToString();
#else
			string rMsg = "An unknown error occured while handling your request.";
			switch (pCode)
			{
				case DomainErrorCode.C_ACADEMICSCHEDULE_TO_DELETE_NOT_FOUND:
				case DomainErrorCode.C_ACADEMICSCHEDULE_TO_SAVE_NOT_FOUND:
				case DomainErrorCode.C_ACADEMICSCHEDULE_TO_SAVE_REGISTRATIONS_OF_NOT_FOUND:
					rMsg = "The schedule was not found in the system.";
					break;
				case DomainErrorCode.C_ACCOUNT_RECOVERY_EMAIL_FAILURE:
					rMsg = "There was a problem sending out the account recovery email.";
					break;
				case DomainErrorCode.C_ACCOUNT_TO_RESET_NOT_FOUND:
				case DomainErrorCode.C_ACCOUNT_TO_SAVE_NOT_FOUND:
					rMsg = "The account was not found in the system.";
					break;
				case DomainErrorCode.C_COURSE_TO_DELETE_NOT_FOUND:
				case DomainErrorCode.C_COURSE_TO_SAVE_NOT_FOUND:
					rMsg = "The course was not found in the system.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_CREATE_ACADEMICSCHEDULE:
					rMsg = "You are not authorized to create a schedule.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_CREATE_ACCOUNT:
					rMsg = "You are not authorized to create an account.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_CREATE_COURSE:
					rMsg = "You are not authorized to create a course.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_CREATE_PERSON:
					rMsg = "You are not authorized to register.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_CREATE_PROGRAM:
					rMsg = "You are not authorized to create a program.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_DELETE_ACADEMICSCHEDULE:
					rMsg = "You are not authorized to delete the schedule.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_DELETE_COURSE:
					rMsg = "You are not authorized to delete the course.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_DELETE_PROGRAM:
					rMsg = "You are not authorized to delete the program.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_RESET_PERSON_ACCOUNT:
					rMsg = "You are not authorized to reset the account.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_SETUP_PERSON:
					rMsg = "You are not authorized to register.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_UPDATE_ACADEMICPLAN:
					rMsg = "You are not authorized to update the plan global settings.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_UPDATE_ACADEMICSCHEDULE:
					rMsg = "You are not authorized to update the schedule.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_UPDATE_ACCOUNT:
					rMsg = "You are not authorized to update the account.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_UPDATE_COURSE:
					rMsg = "You are not authorized to update the course.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_UPDATE_PROGRAM:
					rMsg = "You are not authorized to update the program.";
					break;
				case DomainErrorCode.C_NOT_AUTHORIZED_UPDATE_PERSON:
					rMsg = "You are not authorized to update the personal information.";
					break;
				case DomainErrorCode.C_PERSON_ALREADY_SETUP:
					rMsg = "You are already registered.";
					break;
				case DomainErrorCode.C_PERSON_TO_HELP_RECOVER_ACCOUNT_NOT_FOUND:
					rMsg = "There is no one with the provided email address in our system.";
					break;
				case DomainErrorCode.C_PERSON_TO_RESET_ACCOUNT_NOT_FOUND:
				case DomainErrorCode.C_PERSON_TO_SAVE_NOT_FOUND:
				case DomainErrorCode.C_PERSON_TO_SETUP_NOT_FOUND:
					rMsg = "The person was not found in the system.";
					break;
				case DomainErrorCode.C_PROGRAM_TO_DELETE_NOT_FOUND:
				case DomainErrorCode.C_PROGRAM_TO_SAVE_NOT_FOUND:
					rMsg = "The program was not found in the system.";
					break;
				case DomainErrorCode.C_REGISTRATION_EMAIL_FAILURE:
					rMsg = "There was a problem sending out the registration email.";
					break;
			}

			return rMsg;
#endif
		}
    }
}
